const path = require("path");
const { basePath } = require('./baseConfig')
const fs = require('fs')

// 获取gradle 下面的dependencies
function getGradleDependencies(name) {
  let sdkDir = fs.readdirSync(path.resolve(basePath, 'baseAndroidSDK')).filter(item => item != '.DS_Store')
  sdkDir = sdkDir.filter(item => {
    return item.indexOf('Android') != -1
  })[0]
  let dePath = path.resolve(basePath, 'baseAndroidSDK', sdkDir, 'HBuilder-HelloUniApp/app/build.gradle')
  let str = fs.readFileSync(dePath, 'utf-8');
  const startStr = "// " + name;
  const endStr = (name == '友盟统计' ? '}' : "//");
  console.log('endStrendStrendStrendStrendStr', endStr, name)
  const startIndex = str.indexOf(startStr) + startStr.length;
  const endIndex = str.indexOf(endStr, startIndex);
  const result = str.substring(startIndex, endIndex).trim();
  console.log('resultresultresultresult', result)
  return result;
}
module.exports = {
  moduleConfig: function () {
    return {
      Barcode: {
        title: "扫码功能",
      },
      Bluetooth: {
        title: "蓝牙功能",
      },
      Camera: {
        title: "相机和相册功能",
      },
      Contacts: {
        title: "通讯录功能",
      },
      FaceID: {
        title: "ios人脸识别功能",
      },
      FacialRecognitionVerify: {
        title: "金融级实人认证（需开通配置）",
        sdkKey: 'facialRecognitionVerify',
        sdkFile: {
          file: {
            default: ['utsplugin-release.aar', 'uni-facialRecognitionVerify-release.aar', 'aliyun-face-*.aar', 'aliyun-facelanguage-*.aar', 'aliyun-photinus-*.aar', 'aliyun-wishverify-*.aar', 'Android-AliyunFaceGuard-*.aar', 'APSecuritySDK-DeepSec-*.jiagu.aar'],
          }
        }
      },
      Fingerprint: {
        title: "指纹识别功能",
      },
      Geolocation: {
        title: "定位功能",
        sdkKey: 'geolocation',
        sdkFile: {
          file: {
            baidu: ['baidu-libs-release.aar', 'geolocation-baidu-release.aar'],
            amap: ['geolocation-amap-release.aar'],
          },
          dependencies: {
            amap: getGradleDependencies("高德")
          }
        }
      },
      iBeacon: {
        title: "iBeacon功能",
      },
      LivePusher: {
        title: "直播推流功能",
      },
      Maps: {
        title: "地图功能，只能使用一个服务商",
        sdkKey: 'maps',
        sdkFile: {
          file: {
            baidu: ['baidu-libs-release.aar', 'map-baidu-release.aar'],
            amap: ['weex_amap-release.aar', 'map-amap-release.aar'],
            google: ['weex_google-map-release.aar'],
          },
          dependencies: {
            amap: getGradleDependencies("高德")
          }
        }
      },
      Messaging: {
        title: "短彩邮件消息",
      },
      OAuth: {
        title: "OAuth授权登录",
        sdkKey: 'oauth',
        sdkFile: {
          file: {
            "univerify": [],
            "apple": [],
            "weixin": ['oauth-weixin-release.aar'],
            "qq": ['oauth-qq-release.aar', 'open_sdk_*.jar'],
            "sina": ['openDefault-*.aar', 'oauth-sina-release.aar'],
            "google": ['oauth-google-release.aar'],
            "facebook": ['oauth-facebook-release.aar'],
          },
          javaFile: {
            'weixin': ['WXEntryActivity'],
          },
          configName: 'oauthUserConfig',
          dependencies: {
            weixin: getGradleDependencies("微信")
          }
        }
      },
      Payment: {
        title: "支付功能",
        sdkKey: 'payment',
        sdkFile: {
          file: {
            "appleiap": [],
            "alipay": ['payment-alipay-release.aar'],
            "weixin": ['payment-weixin-release.aar'],
            "paypal": ['payment-paypal-release.aar'],
            "stripe": ['payment-stripe-release.aar'],
            "google": ['payment-google-release.aar']
          },
          dependencies: {
            alipay: getGradleDependencies("支付宝"),
            weixin: getGradleDependencies("微信")
          },
          configName: 'paymentUserConfig',
          javaFile: {
            'weixin': ['WXPayEntryActivity'],
          },
        }
      },
      Push: {
        title: "推送功能",
        sdkKey: 'push',
        sdkFile: {
          file: {
            default: ['aps-release.aar', 'aps-unipush-release.aar', 'gtc.aar', 'gtsdk-*.aar'],
            hms: ['hwp-*.aar'],
            meizu: ['mzp-*.aar', 'mz-push-internal-*.aar'],
            mi: ['xmp-*.aar'],
            oppo: ['oppo-push-*.aar', 'oppo-*.aar'],
            vivo: ['vivo-*.aar'],
            fcm: ['aps-fcm-release.aar'],
          },
          configName: 'uniPushUserConfig',
          outFile: {
            hms: 'agconnect-services.json',
            fcm: 'google-services.json'
          }
        }
      },
      Record: {
        title: "录音功能",
      },
      SecureNetwork: {
        title: "uni云端一体安全网络",
      },
      Share: {
        title: "分享功能",
        sdkKey: 'share',
        sdkFile: {
          file: {
            weixin: ['share-weixin-release.aar'],
            sina: ['share-sina-release.aar', 'openDefault-*.aar'],
            qq: ['share-qq-release.aar', 'open_sdk_*.jar'],
          },
          configName: 'commonUserConfig',
          dependencies: {
            weixin: getGradleDependencies("微信")
          }
        }
      },
      Speech: {
        title: "语音功能，只能使用一个服务商",
        sdkKey: 'speech',
        sdkFile: {
          file: {
            baidu: ['speech-release.aar', 'speech_baidu-release.aar'],
          },
        }
      },
      Statistic: {
        title: "统计功能，只能使用一个服务商",
        sdkKey: 'statics',
        sdkFile: {
          file: {
            umeng: ['statistic-release.aar', 'statistic-umeng-release.aar'],
            google: ['statistic-release.aar', 'statistic-google-release.aar'],
          },
          dependencies: {
            umeng: getGradleDependencies("友盟统计")
          },
          outFile: {
            google: 'google-services.json'
          }
        }
      },
      SQLite: {
        title: "SQLite数据库功能",
      },
      VideoPlayer: {
        title: "视频播放功能",
      },
      'Webview-x5': {
        title: "腾讯X5内核Webview",
        sdkKey: 'webx5',
        sdkFile: {
          file: {
            default: ['webview-x5-release.aar', 'weex_webview-x5-release.aar'],
          }
        }
      },
      UIWebview: {
        title: "苹果UIWebview",
      },
      AD: {
        title: "广告功能",
        sdkKey: 'ad',
        sdkFile: {
          file: {
            "csj": ['ads-release.aar','ads-csj-release.aar','open_ad_sdk.aar'],
            "gdt": ['ads-release.aar','ads-gdt-release.aar','GDTSDK.unionNormal.aar'],
            "ks": ['ads-release.aar','ads-ks-release.aar','ks_adsdk-ad.aar'],
            "ks-content": ['ads-release.aar','ads-ks-content-release.aar','kssdk-allad-content.aar'],
            "gm": ['ads-release.aar','ads-gromore-release.aar','open_ad_sdk.aar'],
            "sigmob": ['ads-release.aar','ads-sigmob-release.aar','windAd.aar','wind-common.aar'],
            "hw": ['ads-release.aar','ads-hw-release.aar'],
            "bd": ['ads-release.aar','ads-bd-release.aar','Baidu_MobAds_SDK.aar']
          },
          configName: 'adUserConfig',
        }
      },
    }
  }
}